request = require 'request'
log4js  = require 'log4js'

log4js.configure
  appenders: [
      type: 'console'
  ]

logger = log4js.getLogger()

json = (uri, obj) ->
  par =
    uri: uri
    method: 'POST'
    json: obj
  request par, (err, resp, body) ->
    logger.error err if err
    logger.warn resp.statusCode if resp.statusCode isnt 200
    logger.info body

qs = (uri, obj) ->
  data =
    client_id: '0922aca0bacc00514983'
    client_secret: '38bdd9a389c7ab36d0e25362706cce0c0af166e8'
    grant_type: 'password'
    utype: 'liuxing@admaster.com.cn'
    password: 'lxing@ad'
  par =
    uri: 'https://open.admaster.com.cn/oauth/access_token'
    method: 'POST'
    body: JSON.stringify data
  request par, (err, resp, body) ->
    logger.error err if err
    logger.warn resp.statusCode if resp.statusCode isnt 200
    logger.info body


do ->
  #json 'http://app.socialmaster.com.cn/api_v2/organizations', {a:1, b:2}
  qs()


